#ifndef _STATE_H_
#define _STATE_H_

#include "stm32f10x.h"
#include "platform_config.h"

// typedef short int16;

// typedef enum {
// 	PACKAGE_NEED_SYNC,
// 	PACKAGE_NEED_LENGTH,
// 	PACKAGE_READ_LENGTH,
// } PackageReadingState_t;

// typedef struct {
// 	char  		sync0;
// 	char  		sync1;
// 	char  		pkgLengthInWORD;
// 	uint16_t  	command;
// 	uint16_t 	*buffer;
// 	uint16_t 	checkSum;
// } SensorXPackage_t;

/* Package SYNC header */
// #define SYNC_HEADER0		(char)85		// U
// #define SYNC_HEADER1		(char)79		// O

/* Command values define */
// #define CMD_ENABLE_TEMP		(uint16_t)0x0031	// 1
// #define CMD_ENABLE_GRAVITY	(uint16_t)0x0032	// 2
// #define CMD_ENABLE_EXTIT	(uint16_t)0x0033	// 3
// #define CMD_AXIS_CORRECT	(uint16_t)0x0034	// 4
// #define CMD_AXIS_RANGESEL	(uint16_t)0x0035	// 5
// #define CMD_GETAXIS_CORRECT	(uint16_t)0x0036	// 6
// #define CMD_DISABLE_MASK	(uint16_t)0x8000		

/* Response value define */
// #define CMD_RESULT			(uint16_t)0x0800	// O

// /* Sensor data packages types */
// #define SENSOR_DAT_TEMP		(uint16_t)0x0041	// A
// #define SENSOR_DAT_TIME		(uint16_t)0x0042	// B
// #define SENSOR_DAT_GRAVITY	(uint16_t)0x0043	// C
// #define SENSOR_DAT_HRTBEAT	(uint16_t)0x0044 	// D

/*******************************************************************************
CMD_ENABLE_TEMP:
	Data[0] = Channel Number
	
CMD_ENABLE_GRAVITY:
	Data[0] = Average Times
	Data[1] = Average Times Shift
	Data[2] = Pipe Deep
	
CMD_ENABLE_EXTIT:
	Data[0] = Channel Number

CMD_AXIS_CORRECT:
	Data[0] = Axis: 'X' or 'Y' or 'Z' 
	Data[1] = +1G: Value
	Data[2] = -1G: Value
	Data[3] = 15: +-1.5G or 60: +-6.0G
	
CMD_AXIS_RANGESEL:
	Data[0] = 15: +-1.5G or 60: +-6.0G
	
CMD_RESULT:
	Data[0] = Time Mark LSB in MS
	Data[1] = Time Mark MSB in MS
	Data[2] = Command Value
	Data[3] = 0 = Passed, 1 = Failed
	
SENSOR_DAT_TEMP:
	Data[0] = Time Mark LSB in MS
	Data[1] = Time Mark MSB in MS
	Data[2] = Tempreture Value
	Data[3] = Sensor type(High 8 bits) and channel value(low 8bits)
			  0: digital 1:analog
	
SENSOR_DAT_TIME:
	Data[0] = Time Mark LSB in MS
	Data[1] = Time Mark MSB in MS
	Data[2] = Int type([CS]0, [LASE]1, 2, 3) | Line Value(0:0x00, 1:0x80)
	
SENSOR_DAT_GRAVITY
	Data[0] = Time Mark LSB in MS
	Data[1] = Time Mark MSB in MS
	Data[2] = x axis ADC value
	Data[3] = y axis ADC value
	Data[4] = z	axis ADC value

SENSOR_DAT_HRTBEAT
	Data[0] = Time Mark LSB in MS
	Data[1] = Time Mark MSB in MS
	Data[2] = Tick Count
*******************************************************************************/


#if (0) // changed for java types
#define SYNC_HEADER		(uint16_t)0x8579
#define CMD_RESP_MARK	0x8000

//****************************************
//	Cmd  = CMD_ENABLE_TEMP
//	Data = None
//****************************************
#define CMD_ENABLE_TEMP		0x0002
#define CMD_DISABLE_TEMP	0x4002

//****************************************
//	Cmd  = CMD_ENABLE_ADCDAT
//	Data[0] = Average Times
//  Data[1] = Average Times Shift
//  Data[2] = Pipe Deep
//****************************************
#define CMD_ENABLE_ADCDAT	0x0004
#define CMD_DISABLE_ADCDAT	0x4004

//****************************************
//	Cmd  = CMD_ENABLE_EXTIT
//	Data = None
//****************************************
#define CMD_ENABLE_EXTIT	0x0008
#define CMD_DISABLE_EXTIT	0x4008

//****************************************
//	Cmd  = CMD_AXIS_CORRECT
//	Data[0] = Axis: 'X' or 'Y' or 'Z' 
//  Data[1] = +1G: Value
//  Data[2] = -1G: Value
//	Data[3] = Range: 1500 or 6000 mG
//****************************************
#define CMD_AXIS_CORRECT	0x0020

//****************************************
//	Cmd  = CMD_X | CMD_RESP_MARK
//	Data[0] = Result
//****************************************
#define CMD_RESULT_OK		0x0000
#define CMD_RESULT_ERROR	0xFFFF

//****************************************
//	Data[0] = Tempreture Value
//****************************************
#define SENSOR_DAT_TEMP		0x0040

//*************************************************************
//	Data[0] = Int type([CS]0, [LASE]1, 2, 3) | Line Value(0, 1)
//  Data[1] = Time Mark LSB in MS
//  Data[2] = Time Mark MSB in MS
//*************************************************************
#define SENSOR_DAT_EINT		0x0080

//*************************************************************
//	Data[0] = x
//  Data[1] = y
//  Data[2] = z
//*************************************************************
#define SENSOR_DAT_ADCV		0x0200

//****************************************
//	Data[1] = Count
//****************************************
#define SENSOR_HEART_BEAT	0x0400


typedef struct {
	uint16_t SYNC;
	uint16_t Type;
	uint16_t Data[3];
} Sensor_Data_t;


typedef struct {
	uint16_t SYNC;
	uint16_t Cmd;
	uint16_t Data[8];
	uint16_t CheckSum;
} Sensor_Package_t;

#endif // if (0)
	

// typedef enum {
// 	STATE_SENSOR_MODE,
// 	STATE_HCAT_MODE,
// 	STATE_UPDATA_MODE,
// } Sensor_State_t;


extern void StateMachine(void);


#endif /* _STATE_H_ */
